package cn.jjzd.info.mapper;

import cn.jjzd.info.pojo.Consultant;
import cn.jjzd.info.response.ConsultantPageResponse;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface ConsultantMapper extends Mapper<Consultant> {

    @Select(" SELECT MAX(serial_number) from tb_consultant ")
    Integer queryMaxSerialNumber();

    @Select({
            "<script>"
                    + " SELECT c.id,c.serial_number serialNumber,c.name,c.good_field goodField,c.description,c.image_path imagePath,c.create_date createDate,cr.area_id areaId,a.area_name areaName,cr.business_type_id businessTypeId,bt.business_name businessTypeName from tb_consultant c "
                    + " INNER JOIN tb_consultant_relation cr on c.id = cr.consultant_id "
                    + " INNER JOIN tb_area a on a.id = cr.area_id "
                    + " INNER JOIN tb_business_type bt on bt.id = cr.business_type_id "
                    + " where c.record_status = 1 and cr.record_status = 1 "
                    + " <when test='areaId != null'> and cr.area_id = #{areaId} </when> "
                    + " <when test='key != null' > and c.name like concat( '%'  ,  #{key} , '%' ) </when> "
                    + " <when test='businessTypeId != null' > and cr.business_type_id = #{businessTypeId} </when> "
                    + " order by c.serial_number ASC "
                    + "</script>"})
    List<ConsultantPageResponse> queryConsultantList(@Param("key") String key, Integer page, Integer rows, @Param("areaId") Long areaId, @Param("businessTypeId") Long businessTypeId);
}
